<template>
	<view class="columnbox content wdh-100">
		<view class="rowbox wdh-100 spb">
			<scroll-view scroll-y class="type-box">
				<view class="rowbox type-title def-col" @click="typeManage">
					<u-icon name="grid" size="36rpx" color="#57bd6a"></u-icon>
					分类管理
				</view>
				<view class="rowbox wdh-100 one-type" :class="{'sel-type':index==curtypppe}"
					v-for="(item,index) in list" :key='index' @click="chooseType(index)">
					<view v-if="curtypppe==index" class="def-bgcol type-line"></view>
					<view class="type-name">{{item.name}}</view>
				</view>
			</scroll-view>
			<scroll-view scroll-y class="goods-list" v-if="list.length>0&&list[curtypppe].List">
				<view class="columnbox wdh-100 one-goods" v-for="(item,index) in list[curtypppe].List">
					<view class="rowbox wdh-100 spb als">
						<image :src="item.image.split(',')[0]" mode="aspectFill" class="goodsimg"></image>
						<view class="columnbox als goods-info">
							<view>{{item.name}}</view>
							<view class="rowbox wdh-100 btn-box">
								<view @click="deletGoods(item.id)" class="rowbox delet-btn">删除</view>
								<view @click="editInfo(item.id)" class="rowbox def-bgcol edit-btn">编辑</view>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="bottom-box wdh-100 rowbox">
			<view @click="addGoods" class="one-btn rowbox def-bgcol">添加商品</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [],
				refreshflag: false,
				curtypppe: 0
			};
		},
		onLoad() {
			// this.getList()
		},
		onShow() {
			this.list = []
			this.getList()
		},
		methods: {
			chooseType(index) {
				this.curtypppe = index
			},
			deletGoods(id) {
				uni.showModal({
					title: '是否要删除该商品',
					success: (res) => {
						if (res.confirm) {
							this.$req.post('/shanghu/gooddel', {
								id: id
							}).then(res => {
								this.list = []
								this.getList()
							})
						}
					}
				})
			},
			getList() {
				this.$req.post('/shanghu/goods', {
					shanghuid: uni.getStorageSync('userInfo').shanghuid
				}).then(res => {
					this.list = res.data.data
				})
			},
			addGoods() {
				uni.navigateTo({
					url: '/pages/goods/add/add'
				})
			},
			typeManage() {
				uni.navigateTo({
					url: '/pages/goods/type/type'
				})
			},
			editInfo(id) {
				uni.navigateTo({
					url: '/pages/goods/add/add?id=' + id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {}

	.bottom-box {
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 10;
		background: #fff;
		padding: 20rpx 20rpx;
		padding-bottom: 40rpx;
		box-shadow: 0 0 4px 2px #eeecef;
	}

	.one-btn {
		width: 100%;
		font-size: 28rpx;
		height: 90rpx;
		border-radius: 20rpx;
		color: #fff;
	}

	.type-box {
		width: 200rpx;
		height: calc(100vh - 160rpx);
		background: #f6f6f6;
		font-size: 28rpx;
	}

	.goods-list {
		width: 550rpx;
		height: calc(100vh - 160rpx);
	}

	.type-title {
		width: 100%;
		padding: 32rpx 20rpx;
	}

	.one-type {
		padding: 32rpx 20rpx;
		position: relative;
	}

	.type-line {
		position: absolute;
		left: 10rpx;
		width: 7rpx;
		height: 32rpx;
	}

	.sel-type {
		background: #fff;
	}

	.type-name {
		width: 140rpx;
		text-overflow: ellipsis;
		white-space: nowrap;
		overflow: hidden;
	}

	.one-goods {
		padding: 20rpx 20rpx;
	}

	.goodsimg {
		width: 150rpx;
		height: 150rpx;
		border-radius: 10rpx;
		border: #f6f6f6 solid 1px;
	}

	.goods-info {
		width: calc(100% - 170rpx);
	}

	.btn-box {
		justify-content: flex-end;
		margin-top: 40rpx;
	}

	.edit-btn,
	.delet-btn {
		width: 100rpx;
		height: 62rpx;
		border-radius: 10rpx;
		font-size: 24rpx;
		margin-left: 20rpx;
	}

	.edit-btn {
		color: #fff;
	}

	.delet-btn {
		border: #eeecef solid 1px;
	}
</style>